Skip to main content

hostname

Introduction

This cheat sheet provides a quick reference for some common hostname commands and concepts. hostname is a command-line utility used to view or set the hostname of a system in Unix-like operating systems.

hostname Concepts

Hostname

The hostname is a label assigned to a device on a network, used to identify it uniquely. It often consists of a name followed by a domain name (FQDN).

  • Display the current hostname:
    hostname

Setting the Hostname

You can change the system's hostname.

  • Set the hostname temporarily (until the next reboot):

    hostname new-hostname
  • Set the hostname persistently (across reboots) in various Linux distributions:

    # On Debian/Ubuntu
    echo "new-hostname" > /etc/hostname
    hostname -F /etc/hostname

    # On Red Hat/CentOS
    nmcli general hostname new-hostname

Displaying the FQDN

The Fully Qualified Domain Name (FQDN) includes both the hostname and the domain name.

  • Display the FQDN of the system:
    hostname -f

Domain Name

The domain name is the part of the FQDN that follows the hostname.

  • Display the domain name of the system:
    dnsdomainname

hostname Command-Line

  • Display the current hostname:

    hostname
  • Set the hostname temporarily (until the next reboot):

    hostname new-hostname
  • Set the hostname persistently (across reboots) on Debian/Ubuntu:

    echo "new-hostname" > /etc/hostname
    hostname -F /etc/hostname
  • Display the FQDN of the system:

    hostname -f
  • Display the domain name of the system:

    dnsdomainname

Conclusion

This cheat sheet covers some common hostname commands and concepts. hostname is a fundamental tool for managing the hostname and FQDN of a system in Unix-like operating systems, helping identify and locate devices on a network; refer to the official hostname documentation for more in-depth information and advanced usage.